# Contributor: Jake Buchholz Göktürk <tomalok@gmail.com>
# Maintainer: Jake Buchholz Göktürk <tomalok@gmail.com>
pkgname=docker-cli-buildx
pkgver=0.12.0
pkgrel=0
pkgdesc="A Docker CLI plugin for extended build capabilities"
url="https://docs.docker.com/engine/reference/commandline/buildx_build"
arch="all"
license="Apache-2.0"
makedepends="go"
options="net"
source="buildx-$pkgver.tar.gz::https://github.com/docker/buildx/archive/v$pkgver.tar.gz"

_buildx_installdir="/usr/libexec/docker/cli-plugins"

builddir="$srcdir"/buildx-"$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	PKG=github.com/docker/buildx
	local ldflags="-X $PKG/version.Version=v$pkgver -X $PKG/version.Revision=$_commit -X $PKG/version.Package=$PKG"
	go build -v -modcacherw -ldflags "$ldflags" -o docker-buildx ./cmd/buildx
}

check() {
	# bake and gitutil tests do not succeed inside abuild environment
	local pkgs="$(go list -modcacherw ./... | grep -Ev '(bake|gitutil)')"
	go test -modcacherw -short $pkgs
	./docker-buildx version
}

package() {
	# this is circular to have top-level, so depend on it in package itself
	depends="docker-cli"
	install -Dm755 docker-buildx "$pkgdir$_buildx_installdir"/docker-buildx
}

sha512sums="
1efd329dd979e0d405d6b8490327c5702eb35ca4dd53b76f924833df1d8e343d350a912d31d671acf35a8555fff01a8dd3311d0a29429fa2f296ad7b837da105  buildx-0.12.0.tar.gz
"
